<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$intLID = (int)$data["LottoID_n"];
if($intLID == 0)$intLID = $_MemInitLottoID;
if($intLID == 0)$intLID = 1;
getGameScoreFile($intLID);

$strGameDate = $_data["GameDate"];
$arrGD = getLastOneGambleData($intLID);

$arrLotto = GetLottoData($intLID);
if(!$arrLotto)ErrMsgOutputHTML("LoginError", "", 1);

$fp = @file($strTemplatePath."Add.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

$strGameTime = "";
$strEndGameTime = "";
$arrOSerialDiff = array(5 => true, 6 => false, 7 => false, 8 => true);
$arrTimeRange = array(5 => 50, 6 => 23, 7 => 120, 8 => 84);
$arrZero = array(5 => 2, 6 => 2, 7 => 3, 8 => 2);
$strZero = "%0".$arrZero[$intLID]."s";
$intDenominator = pow(10, $arrZero[$intLID]);

if($_arrPermitTimeItems[$intLID]){
	$arrTimeParam = unserialize($arrLotto["TimeParam"]);
	$strNowTime = TimeForm($strGameDate, date("H:i:s"), "H:i:s");
	for($intNo = 1; $intNo <= $arrTimeRange[$intLID]; $intNo++){
		if($arrTimeParam["EndGameTime"][$intNo] <= $strNowTime)continue;
		$intSerialNo = str_replace("-", "", $strGameDate).sprintf($strZero, $intNo);
		$strGameTime = $arrTimeParam["GameTime"][$intNo];
		$strEndGameTime = $arrTimeParam["EndGameTime"][$intNo];

		if($arrOSerialDiff[$intLID]){
			if($arrGD["OSerialNo"] < 201000101){
				$strDays = DateForm($strGameDate, date("H:i:s"), "z");
				$strYear = DateForm($strGameDate, date("H:i:s"), "Y");
				$intOSerialNo = $strYear.sprintf("%03s", $strDays).sprintf($strZero, $intNo);
			}elseif($arrGD["OSerialNo"] % 100 == 50){
				$intOSerialNo = floor($arrGD["OSerialNo"] / $intDenominator + 1).sprintf($strZero, $intNo);
			}else{
				$intOSerialNo = floor($arrGD["OSerialNo"] / $intDenominator).sprintf($strZero, $intNo);
			}

			if($intLID == 8){
				if(floor($intSerialNo / $intDenominator) - floor($arrGD["SerialNo"] / $intDenominator) > 0){
					$intOSerialNo = $arrGD["OSerialNo"] + 1;
				}else{
					$intOSerialNo = $arrGD["OSerialNo"] + ($intSerialNo - $arrGD["SerialNo"]);
				}
			}
		}else{
			$intOSerialNo = $intSerialNo;
		}
		break;
	}
}else{
	$intSerialNo = ($arrGD["GameDate"] > date("Y"))?($arrGD["SerialNo"]+1):1;
	$fp = preg_replace("/<!-- @ OGameNo Sd @ \/\/-->.+<!-- @ OGameNo End @ \/\/-->/s", "", $fp);
}
$fp = str_replace("{intLang}", $_intLang, $fp);
$fp = str_replace("{LType}", $arrLotto["LType"], $fp);
$fp = str_replace("{ShowSerialNo}", $intSerialNo, $fp);
$fp = str_replace("{ShowOSerialNo}", $intOSerialNo, $fp);
$fp = str_replace("{ShowGameDate}", $strGameDate, $fp);
$fp = str_replace("{ShowGameTime}", $strGameTime, $fp);
$fp = str_replace("{ShowEndGameTime}", $strEndGameTime, $fp);

while(list($k, $v) = each($_strCompetition)){
	$fp = str_replace("{".$k."}", $v, $fp);
}

$strSelect = "<select name='data[LottoID_n]' onchange='ChangeLID();'>\n";
$strSelect .= "<option value=\"\">--select--</option>\n";
$arrLottoPower = getLottoUsePowerArray();
foreach($_arrLotto as $intLottoID => $arrLottoData){
	if(!in_array($intLottoID, $arrLottoPower))continue;

	$strSelect .= "<option value='".$intLottoID."' ".(($intLottoID == $intLID)?"selected":"").">".$arrLottoData["Lotto_".$_intLang]."</option>\n";
}
$strSelect .= "</select>\n";
//$strSelect = RelationType3("data[LottoID_n]", "`bet_Lotto`", $intLID, " ID, Lotto_".$_intLang." as Value ", "onchange='ChangeLID();'");;
$fp = str_replace("{LottoIDSelectTag}", $strSelect, $fp);

if($arrLotto["LType"] == 1){
	$fp = preg_replace("/<!-- @ HiddenEndGTime Sd @ \/\/-->.+<!-- @ HiddenEndGTime End @ \/\/-->/s", "", $fp);
}else{
	$fp = preg_replace("/<!-- @ ShowEndGTime Sd @ \/\/-->.+<!-- @ ShowEndGTime End @ \/\/-->/s", "", $fp);
}

//輸出
WebOutputHTML($fp, 1);
?>